﻿using System.Windows;
using System.Windows.Controls;
using Kindohm.KSynth.Library;

namespace Kindohm.KSynth.Droner
{
    public partial class MainPage : UserControl
    {
        Mixer mixer;
        uint count;

		
        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }


        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            StereoPcmStreamSource source = new StereoPcmStreamSource();
            WaveTable.InitializeWaveForms();
            this.mixer = new Mixer();
            this.AddChannel();
            source.Input = mixer;
            this.media.SetSource(source);
        }

        void AddChannel()
        {
            count += 1;
            ChannelControl channel = new ChannelControl(this.mixer, "Channel " + count.ToString());
            channel.Deleted += new System.EventHandler(channel_Deleted);
            this.container.Children.Add(channel);
        }

        void channel_Deleted(object sender, System.EventArgs e)
        {
            ChannelControl channel = sender as ChannelControl;
            channel.Deleted -= channel_Deleted;
            this.container.Children.Remove(channel);
        }

        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            this.AddChannel();
        }
    }
}
